package com.wcj.study.multidatasource.config;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * TODO 添加类描述
 * 
 * @author 汪长军 Email：changjunwang@xinhe99.com
 * @date 2018-09-28 下午3:50:56
 * @copyright 信和上融网络科技(北京)有限公司
 */
@Configuration
@ConfigurationProperties(prefix = "spring.datasource.multi")
public class MultiDataSourceProperties {

    /**
     * 默认数据源
     */
    private String defaultDsGroup;

    /**
     * mysql数据源组,key为组名称,value为数据源
     */
    private Map<String, DsGroupProperties> instance = new HashMap<>();

    /**
     * @return the defaultDsGroup
     */
    public String getDefaultDsGroup() {
        return defaultDsGroup;
    }

    /**
     * @param defaultDsGroup the defaultDsGroup to set
     */
    public void setDefaultDsGroup(String defaultDsGroup) {
        this.defaultDsGroup = defaultDsGroup;
    }

    /**
     * @return the instance
     */
    public Map<String, DsGroupProperties> getInstance() {
        return instance;
    }

    /**
     * @param instance the instance to set
     */
    public void setInstance(Map<String, DsGroupProperties> instance) {
        this.instance = instance;
    }

    /**
     * 
     * mysql数据源组,一个组是一个独立的部署单元
     * 
     * @author 汪长军 Email：changjunwang@xinhe99.com
     * @date 2019-01-07 下午4:28:07
     * @copyright 信和上融网络科技(北京)有限公司
     */
    public static class DsGroupProperties {

        /**
         * 写操作
         */
        private DsProperties write;

        /**
         * 读操作
         */
        private DsProperties read;

        /**
         * @return the write
         */
        public DsProperties getWrite() {
            return write;
        }

        /**
         * @param write the write to set
         */
        public void setWrite(DsProperties write) {
            this.write = write;
        }

        /**
         * @return the read
         */
        public DsProperties getRead() {
            return read;
        }

        /**
         * @param read the read to set
         */
        public void setRead(DsProperties read) {
            this.read = read;
        }

    }

    public static class DsProperties {

        /**
         * 数据源bean名称
         */
        private List<String> dsBeanNames = new ArrayList<>();

        /**
         * 拦截的方法,支持正则,该方法是读操作还是写操作
         */
        private List<String> opMethods = new ArrayList<>();

        /**
         * @return the dsBeanNames
         */
        public List<String> getDsBeanNames() {
            return dsBeanNames;
        }

        /**
         * @param dsBeanNames the dsBeanNames to set
         */
        public void setDsBeanNames(List<String> dsBeanNames) {
            this.dsBeanNames = dsBeanNames;
        }

        /**
         * @return the opMethods
         */
        public List<String> getOpMethods() {
            return opMethods;
        }

        /**
         * @param opMethods the opMethods to set
         */
        public void setOpMethods(List<String> opMethods) {
            this.opMethods = opMethods;
        }

    }

}